﻿using AutoMapper;

using PLCS.Application.Contracts.ConfigApp.Dtos;
using PLCS.Application.Contracts.EquipmentApp.Dtos;
using PLCS.Application.Contracts.ErrorLibraryApp.Dtos;
using PLCS.Application.Contracts.ErrorLogApp.Dtos;
using PLCS.Application.Contracts.HisOrderApp.Dtos;
using PLCS.Application.Contracts.HisTaskApp.Dtos;
using PLCS.Application.Contracts.InterfaceApp.Dtos;
using PLCS.Application.Contracts.LogShowApp.Dtos;
using PLCS.Application.Contracts.MenuApp.Dtos;
using PLCS.Application.Contracts.OrderApp.Dtos;
using PLCS.Application.Contracts.PLCConfigApp.Dtos;
using PLCS.Application.Contracts.PLCReadDataApp.Dtos;
using PLCS.Application.Contracts.ProcessApp.Dtos;
using PLCS.Application.Contracts.RoleApp.Dtos;
using PLCS.Application.Contracts.SolutionApp.Dtos;
using PLCS.Application.Contracts.StationApp.Dtos;
using PLCS.Application.Contracts.TaskApp.Dtos;
using PLCS.Application.Contracts.TrayApp.Dtos;
using PLCS.Application.Contracts.UserApp.Dtos;
using PLCS.Domain.Configs;
using PLCS.Domain.Equipments;
using PLCS.Domain.ErrorLibraries;
using PLCS.Domain.Logs;
using PLCS.Domain.Menus;
using PLCS.Domain.Orders;
using PLCS.Domain.PLCConfigs;
using PLCS.Domain.Processes;
using PLCS.Domain.Roles;
using PLCS.Domain.Solutions;
using PLCS.Domain.Stations;
using PLCS.Domain.Tasks;
using PLCS.Domain.Trays;
using PLCS.Domain.Users;

namespace PLCS.Application;

public class PLCSProfile : Profile
{
    public PLCSProfile()
    {
        CreateMap<User, UserDto>().ReverseMap();
        CreateMap<UserEditDto, User>().ReverseMap();
        CreateMap<Menu, MenuDto>().ReverseMap();
        CreateMap<MenuEditDto, Menu>().ReverseMap();
        CreateMap<Role, RoleDto>().ReverseMap();
        CreateMap<RoleEditDto, Role>().ReverseMap();

        CreateMap<Order, OrderDto>().ReverseMap();
        CreateMap<OrderEditDto, Order>().ReverseMap();

        CreateMap<HisOrder, HisOrderDto>().ReverseMap();
        CreateMap<HisOrderEditDto, HisOrder>().ReverseMap();

        CreateMap<OrderRunningCondition, OrderRunningConditionDto>().ReverseMap();

        CreateMap<TaskModel, TaskDto>().ReverseMap();
        CreateMap<TaskModel, HisTask>().ReverseMap();
        CreateMap<TaskEditDto, TaskModel>().ReverseMap();
        CreateMap<Instruction, InstructionDto>().ReverseMap();
        CreateMap<HisInstruction, HisInstructionDto>().ReverseMap();
        CreateMap<InstructionEditDto, Instruction>().ReverseMap();
        CreateMap<HisTask, HisTaskDto>().ReverseMap();
        CreateMap<HisTaskEditDto, HisTask>().ReverseMap();

        CreateMap<Station, StationDto>().ReverseMap();
        CreateMap<Tray, TrayDto>()
             .ForMember(dest => dest.StaNum, opt => opt.MapFrom(src => src.Station.StaNum))
             .ReverseMap();

        CreateMap<TrayEditDto, Tray>();
        CreateMap<StationEditDto, Station>().AfterMap((src, dest) =>
        {
            dest.InitalCanOutAndInStatus();
        }).ReverseMap();
        CreateMap<Equipment, EquipmentDto>().ReverseMap();
        CreateMap<EquipmentEditDto, Equipment>().ReverseMap();

        CreateMap<Process, ProcessDto>().ReverseMap();
        CreateMap<ProcessEditDto, Process>().ReverseMap();
        CreateMap<Trigger, TriggerDto>().ReverseMap();
        CreateMap<TriggerEditDto, Trigger>().ReverseMap();
        CreateMap<Solution, SolutionDto>().ReverseMap();
        CreateMap<SolutionEditDto, Solution>().ReverseMap();
        CreateMap<SolutionStep, SolutionStepDto>().ReverseMap();
        CreateMap<SolutionStepEditDto, SolutionStep>().ReverseMap();

        CreateMap<PLCConfig, PLCConfigDto>().ReverseMap();
        CreateMap<PLCConfigEditDto, PLCConfig>().ReverseMap();
        CreateMap<PLCReadData, PLCReadDataDto>()
            .ForMember(dest => dest.PLCConfigNo, opt => opt.MapFrom(src => src.PLCConfig.PLCNo))
            .ReverseMap();
        CreateMap<PLCReadDataEditDto, PLCReadData>().ReverseMap();
        CreateMap<Config, ConfigDto>().ReverseMap();
        CreateMap<ConfigEditDto, Config>().ReverseMap();

        CreateMap<InterfaceLog, InterfaceLogDto>().ReverseMap();
        CreateMap<OperationLog, OperationLogDto>().ReverseMap();
        CreateMap<OperationLogEditDto, OperationLog>().ReverseMap();
        CreateMap<ErrorLog, ErrorLogDto>().ReverseMap();
        CreateMap<ErrorLogEditDto, ErrorLog>().ReverseMap();
        CreateMap<ErrorLibrary, ErrorLibraryDto>().ReverseMap();
        CreateMap<ErrorLibraryDto, ErrorLibraryEditDto>().ReverseMap();
    }
}